package ai.people.platform.archives.controller;

import ai.people.netmon.framework.domain.key.account.request.CollisionRequest;
import ai.people.netmon.framework.domain.key.account.request.ExtendRequest;
import ai.people.netmon.framework.domain.key.account.request.SearchRequest;
import ai.people.netmon.framework.domain.key.account.vo.CollisionResultVO;
import ai.people.netmon.framework.domain.key.account.vo.ExtendVO;
import ai.people.netmon.framework.domain.key.account.vo.KeyAccountGraph;
import ai.people.netmon.framework.domain.key.account.vo.SearchListVO;
import ai.people.netmon.framework.domain.warning.request.account.AccountRegisterInfoRequest;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import ai.people.platform.archives.service.KeyAccountRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * 重点账号-关系图谱和辅助落查接口
 *
 * @author zhenglin
 * @date 2022/7/26
 */
@RefreshScope
@RestController
@RequestMapping("/keyAccount")
public class KeyAccountController {

    @Autowired
    KeyAccountRelationService keyAccountRelationService;


    /**
     * 关系图谱-查看图
     *
     * @param id 重点账号ID
     * @return {@link Result}<{@link KeyAccountGraph}>
     * @throws Exception 异常
     */
    @GetMapping("/graph/{id}")
    public Result<KeyAccountGraph> getGraph(@PathVariable("id") Long id) throws Exception {
        KeyAccountGraph obj = keyAccountRelationService.getGraph(id);
        return ResultUtil.success(obj);
    }

    /**
     * 关系图谱-更新图
     *
     * @param vo 签证官
     * @return {@link Result}<{@link Boolean}>
     * @throws Exception 异常
     */
    @PostMapping("/graph/update")
    public Result<Boolean> updateGraph(@Validated @RequestBody KeyAccountGraph vo) throws Exception {
        keyAccountRelationService.updateGraph(vo);
        return ResultUtil.success();
    }

    /**
     * 关系图谱-扩线
     *
     * @param request 请求
     * @return {@link Result}<{@link ExtendVO}>
     * @throws Exception 异常
     */
    @PostMapping("/extend")
    public Result<ExtendVO> extend(@Validated @RequestBody ExtendRequest request) throws Exception {
        ExtendVO res = keyAccountRelationService.extend(request);
        return ResultUtil.success(res);
    }


    /**
     * 关系图谱-碰撞
     *
     * @param request 请求
     * @return {@link Result}<{@link CollisionResultVO}>
     * @throws Exception 异常
     */
    @PostMapping("/collision")
    public Result<CollisionResultVO> collision(@Validated @RequestBody CollisionRequest request) throws Exception {
        CollisionResultVO res = keyAccountRelationService.collision(request);
        return ResultUtil.success(res);
    }

    /**
     * 辅助落查-查看图
     *
     * @param id id
     * @return {@link Result}<{@link KeyAccountGraph}>
     * @throws Exception 异常
     */
    @GetMapping("/search/graph/{id}")
    public Result<KeyAccountGraph> searchGraph(@PathVariable("id") Long id) throws Exception {
        KeyAccountGraph obj = keyAccountRelationService.searchGraph(id);
        return ResultUtil.success(obj);
    }

    /**
     * 辅助落查-更新图
     *
     * @param graph 图
     * @return {@link Result}<{@link Boolean}>
     * @throws Exception 异常
     */
    @PostMapping("/search/graph/update")
    public Result<Boolean> updateSearchGraph(@Validated @RequestBody KeyAccountGraph graph) throws Exception {
        keyAccountRelationService.updateSearchGraph(graph);
        return ResultUtil.success();
    }

    /**
     * 辅助落查-点击开始落查
     *
     * @param request 请求
     * @return {@link Result}<{@link List}<{@link SearchListVO}>>
     */
    @PostMapping("/search/graph/find")
    public Result<List<SearchListVO>> searchStartFind(@Validated @RequestBody SearchRequest request) throws InterruptedException {
        List<SearchListVO> res = keyAccountRelationService.searchStartFind(request);
        return ResultUtil.success(res);
    }

    /**
     * 检查是否能更新基本信息
     *
     * @param accountRegisterInfoRequest 账户注册信息请求
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/checkUpdate")
    public Result<Boolean> checkUpdate(@Validated @RequestBody AccountRegisterInfoRequest accountRegisterInfoRequest) throws Exception {
        boolean f = keyAccountRelationService.checkUpdate(accountRegisterInfoRequest);
        return ResultUtil.success(f);
    }

}
